package com.cyf.utils.datetime;

//import org.apache.commons.net.ntp.NTPUDPClient;
//import org.apache.commons.net.ntp.TimeInfo;
//import org.apache.commons.net.ntp.TimeStamp;

import java.io.IOException;
import java.net.InetAddress;
import java.util.Date;

/**
 * Created by Administrator on 2019/7/19.
 */
public class NtpUtil {

//    public static Date getNtpDate() throws IOException {
//            NTPUDPClient timeClient = new NTPUDPClient();
////			String timeServerUrl = "192.168.20.1";
//            String timeServerUrl = "0.debian.pool.ntp.org";
//            InetAddress timeServerAddress = InetAddress.getByName(timeServerUrl);
//            timeClient.setDefaultTimeout(15000);
//            TimeInfo timeInfo = timeClient.getTime(timeServerAddress);
//            TimeStamp timeStamp = timeInfo.getMessage().getTransmitTimeStamp();
//            Date date = timeStamp.getDate();
//            return date;
//    }

//    public static void main(String[] args) {
//        try {
//            Date ntpDate = getNtpDate();
//            Calendar calendar = Calendar.getInstance();
//            calendar.setTime(ntpDate);
//            int year=calendar.get(Calendar.YEAR)-2000;
//            int month=calendar.get(Calendar.MONTH)+1;
//            int day=calendar.get(Calendar.DAY_OF_MONTH);
//            int hour=calendar.get(Calendar.HOUR);
//            int min=calendar.get(Calendar.MINUTE);
//            int sec=calendar.get(Calendar.SECOND);
//            System.out.println(ntpDate);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
}
